package com.witframework.plugin.jbossrules;

import org.drools.RuleBase;
import org.drools.WorkingMemory;


/**
 * 缓存与管理RuleBase的类
 */
public class RuleBaseManager {
	private RuleBaseLoader ruleBaseLoader;

	private RuleBase ruleBase;

	public void setRuleBaseLoader(RuleBaseLoader ruleBaseLoader) {
		this.ruleBaseLoader = ruleBaseLoader;
	}
	public void updateRuleBase(RuleBase ruleBase){
		if(ruleBase!=null)
			this.ruleBase = ruleBase;
	}
	public WorkingMemory getSession() {
		if (ruleBase == null) {
			ruleBase = ruleBaseLoader.buildRuleBase();
		}
		WorkingMemory wm = ruleBase.newStatefulSession();
		return wm;
	}

}
